package org.wmq.positiontoshop.init;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.wmq.positiontoshop.service.BloomFilterService;

/**
 * 布隆过滤器初始化器
 * 在应用启动时初始化布隆过滤器数据
 */
@Component
@Slf4j
public class BloomFilterInitializer implements ApplicationRunner {
    
    @Autowired
    private BloomFilterService bloomFilterService;
    
    /**
     * 在应用启动后执行初始化操作
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("应用启动，开始初始化布隆过滤器数据");
        
        try {
            // 初始化店铺ID布隆过滤器
            bloomFilterService.initializeShopIdBloomFilter();
            log.info("布隆过滤器初始化完成");
        } catch (Exception e) {
            // 如果初始化失败，记录错误但不影响应用启动
            log.error("布隆过滤器初始化失败，应用继续启动", e);
        }
    }
}